<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生登录</title>
    <link rel="stylesheet" href="css/login.css">
</head>
<body>
		<div class="m-login-bg">
			<div class="m-login">
				<h3>学生成绩管理查询系统</h3>
				<div class="m-login-warp">
					<form class="form">
						<div class="form-item">
							<input type="text" name="userName" required lay-verify="required" placeholder="用户名" autocomplete="off" class="input" v-model="login.userName"><br><br>
						</div>
						<div class="form-item">
							<input type="password" name="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="input" v-model="login.password"><br><br>
						</div>
						<div class="form-item">
							<select v-model="Type">
								<option checked="">学生</option>
								<option>教师</option>
							</select>
						</div>

						<div class="form-item m-login-btn">
							<div class="inline">
								<button type="button" class="btn btn-normal" @click="checkLogin" >登录</button>
								<button type="button" class="btn btn-primary" @click="Register">注册</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<script src="js/vue/vue2.5.js"></script>
		<script src="js/vue/axios.min.js"></script>
		<script src="js/jquery.js"></script>
		<script src="js/layer/layer.js"></script>
		<script>
			new Vue({
				el:'.m-login-bg',
				data:{
					login:{
						userName:'',
						password:''
					},
					Type:''
				},
				methods:{
					checkLogin(){
						if(!this.checkForm()) return;
						axios.get('login/query',{params:{loginName:this.login.userName}})
							.then(resp=>{
								if(resp.data.loginPw == this.login.password) {
									layer.msg('登陆成功！');
									console.log(resp.data);
									setTimeout(()=>{
										if(resp.data.loginType == 1) {
											location.href='MinAdmin.html?loginId=' + resp.data.loginId;
										}else {
											location.href='MinStudent.html?loginId=' + resp.data.loginId;
										}
									},500);
								}
							})
					},
					Register() {
						location.href = 'register.html';
					},
					checkForm(){
						let r = /^\d{6}$/;
						if(!r.test(this.login.password)) {
							layer.alert('密码必须为六位数字！');
							return false;
						}
						return true;
					}
				}
			})
		</script>
</body>
</html>